package com.example.myblog.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yx
 */
@Configuration
public class RabbitMQConfig {
    public static final String QUEUE_BLOG_SAVE = "queue.blog.save";
    public static final String QUEUE_BLOG_REMOVE = "queue.blog.remove";
    public static final String BLOG_EXCHANGE = "blog.exchange";
    public static final String KEY_BLOG_SAVE = "key.blog.save";
    public static final String KEY_BLOG_REMOVE = "key.blog.remove";

    @Bean
    public Queue queueBlogSave() {
        return new Queue(QUEUE_BLOG_SAVE);
    }

    @Bean
    public Queue queueBlogRemove() {
        return new Queue(QUEUE_BLOG_REMOVE);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(BLOG_EXCHANGE);
    }
    @Bean
    public Binding bindBlogSave() {
        return BindingBuilder.bind(queueBlogSave()).to(topicExchange()).with(KEY_BLOG_SAVE);
    }
    @Bean
    public Binding bingBlogRemove() {
        return BindingBuilder.bind(queueBlogRemove()).to(topicExchange()).with(KEY_BLOG_REMOVE);
    }


}
